Skip to content

C#: Include parameters and their defaults in the CFG#21759

Draft
hvitved wants to merge 8 commits intogithub:mainfrom
hvitved:csharp/cfg-params
Draft

C#: Include parameters and their defaults in the CFG#21759
hvitved wants to merge 8 commits intogithub:mainfrom
hvitved:csharp/cfg-params

Conversation

@hvitved
Copy link
Copy Markdown
Contributor

@hvitved hvitved commented Apr 27, 2026

This PR adds support in the shared CFG library for including parameters and their default values, and applies this to C# (even though, technically, default values are inlined into the callers).

We use Matching successors to denote whether an argument has been supplied or not. For example, this C# program

string M1(bool b, string s = "", int i = 0)
{
    return b + s + i;
}

gives rise to the following CFG (skipping the parts inside the body):

flowchart TD
1["Entry"]
10["After i [no-match]"]
11["i"]
12["0"]
13["{...}"]
4["b"]
5["After s [match]"]
6["After s [no-match]"]
7["s"]
8['""']
9["After i [match]"]

1 --> 4
4 --> 7
5 --> 11
6 --> 8
7 -- match --> 5
7 -- no-match --> 6
8 --> 11
9 --> 13
10 --> 12
11 -- match --> 9
11 -- no-match --> 10
12 --> 13
Loading

With parameters and their defaults added to the CFG, we replace existing SSA definitions at function entry with their CFG nodes (except when functions have multiple bodies), and we also add SSA definitions corresponding to defaults, which means that phi nodes will automatically be inserted.

Commit-by-commit review is strongly encouraged.

@hvitved hvitved force-pushed the csharp/cfg-params branch 8 times, most recently from 764c65c to f09d4e5 Compare April 28, 2026 09:55
Comment thread csharp/ql/lib/semmle/code/csharp/dataflow/Nullness.qll Fixed
@hvitved hvitved force-pushed the csharp/cfg-params branch 2 times, most recently from 3b34de4 to 889f721 Compare April 28, 2026 12:05
@hvitved hvitved force-pushed the csharp/cfg-params branch from 889f721 to 12d3acf Compare April 28, 2026 12:24
@hvitved hvitved force-pushed the csharp/cfg-params branch from 12d3acf to 3a62ffa Compare April 28, 2026 12:45
@hvitved
Copy link
Copy Markdown
Contributor Author

hvitved commented Apr 28, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants